<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

// Define cookie name and default (fallback) style.
$styleCookieName = $templateName . "TemplateStyle";
$widthCookieName = $templateName . "TemplateWidth";
$style = 'default';
$width = 'w960px';

// Check if a URL parameter with style information is set:
// e.g. http://www.demosite.com/index.php?style=style1
// if this parameter is set and style1.css file exists, 
// then set a cookie and assign style1.css as current stylesheet
// otherwise use the default/fallback style and set cookie

if (isset($_GET['style']) && $_GET['style'] != "") {
	$styleSheetURL = "templates/" . $this->template . "/css/styles/" . $_GET['style'] . ".css";
	if (file_exists($styleSheetURL)) {
		$style = $_GET['style'];
	}
	$expire=time()+60*60*24*30;
	setcookie($styleCookieName, $style, $expire);
	$styleSheetURL="<link rel=\"stylesheet\" href=\"". $this->baseurl . "/templates/" . $this->template . "/css/styles/" . $style . ".css\" />";
	echo $styleSheetURL;
} else {
	// If no valid stylesheet found or no URL parameter is set
	// Then check if a cookie is set or use default stylesheet for new users.
	if(!isset($_COOKIE[$styleCookieName])){
		// DEFAULT STYLESHEET
		$expire=time()+60*60*24*30;
		setcookie($styleCookieName, $style, $expire);
		$styleSheetURL="<link rel=\"stylesheet\" href=\"". $this->baseurl . "/templates/" . $this->template . "/css/styles/" . $style . ".css\" />";
		echo $styleSheetURL;
	} else {
		// STYLE FROM COOKIE
		$style = $_COOKIE[$styleCookieName];
		$styleSheetURL="<link rel=\"stylesheet\" href=\"". $this->baseurl . "/templates/" . $this->template . "/css/styles/" . $style . ".css\" />";
		echo $styleSheetURL;
	}
}



// Check if a URL parameter with style information is set:
// e.g. http://www.demosite.com/index.php?style=style1
// if this parameter is set and style1.css file exists, 
// then set a cookie and assign style1.css as current stylesheet
// otherwise use the default/fallback style and set cookie

if (isset($_GET['width']) && $_GET['width'] != "") {
	$expire=time()+60*60*24*30;
	$width = $_GET['width'];
	setcookie($widthCookieName, $width, $expire);
} else {
	// If no valid stylesheet found or no URL parameter is set
	// Then check if a cookie is set or use default stylesheet for new users.
	if(!isset($_COOKIE[$widthCookieName])){
		// DEFAULT STYLESHEET
		$expire=time()+60*60*24*30;
		setcookie($widthCookieName, $width, $expire);
	} else {
		// STYLE FROM COOKIE
		$width = $_COOKIE[$widthCookieName];
	}
}
$bodyClass = $width . $pageclass . $menuAnimationClass ;
?>
